package com.xingmei;

import java.util.concurrent.*;
import java.util.concurrent.locks.ReentrantLock;

@SuppressWarnings("ALL")
public class Main {
    public static void main(String[] args) throws InterruptedException {
        User[] users = new User[110];
        System.out.println(users.length);
        System.out.println(users[9]);
        int[] ages = new int[10];
        System.out.println(ages[7]);
        ReentrantLock lock = new ReentrantLock();
        ClassLoader classLoader = lock.getClass().getClassLoader();
        System.out.println(classLoader);
        int[] ary = {1,2,3};
        int num=1;
        Integer integer = new Integer(33);
        String str = "a";
        User user = new User();
        user.setAge(18);
        user.setName("xiaoming");
        User user1 = user;
        user1.setName("ssssss");
        ClassLoader userClassLoader = user.getClass().getClassLoader();
        System.out.println(userClassLoader);
        ClassLoader parentClassLoader = userClassLoader.getParent();
        System.out.println(parentClassLoader);
        ThreadLocal threadLocal = new ThreadLocal();
        InheritableThreadLocal inheritableThreadLocal = new InheritableThreadLocal();
        threadLocal.set(user);
        inheritableThreadLocal.set(user);
        Thread childThread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("=======" + inheritableThreadLocal.get().toString());
                System.out.println(threadLocal.get());
            }
        });
        Callable callable = new Callable() {
            @Override
            public Object call() throws Exception {
                return null;
            }
        };
        Runnable runnable = new Runnable() {
            @Override
            public void run() {

            }
        };

        childThread.start();
        // 复杂对象应用传递、基本类型值传递
        changeUser(user);
        changeName(str);
        changeInt(integer);
        changeArray(ary);
        System.out.println("-----" + user.toString());
        System.out.println("-----" + str);
        System.out.println("-----" + integer);
        CountDownLatch countDownLatch = new CountDownLatch(1);
        countDownLatch.countDown();
        countDownLatch.await();
        BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(); // 默认行为，FIFO
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                1, // corePoolSize
                4, // maximumPoolSize
                30, // keepAliveTime
                TimeUnit.SECONDS,
                queue // 使用默认队列行为
        );

        // 提交任务
        for (int i = 0; i < 10; i++) {
            final int taskId = i;
            executor.submit(() -> {
                System.out.println("Executing task " + taskId);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            });
        }
        Thread.sleep(10000);
        int threadNum = executor.getLargestPoolSize();
        System.out.println("------threadNum:" + threadNum);
        // 关闭executor，不再接受新任务，并且在完成所有已经在队列中的任务后关闭
        executor.shutdown();
        int size = 10;
        float half = size >> 1;
        System.out.println("------half:" + half);
    }

    private static void changeUser (User user) {
        user.setAge(180);
        user.setName("11");
    }
    private static void changeName(String name ){
        name="a-b";
    }

    private static void changeInt(Integer integer ) {
        integer = 1;
    }

    private static void changeArray(int[] list ) {
        int[] newArray={1,2,3,4};
        list=newArray;
    }
}
